import os, subprocess

def PhonyTarget(target, action):
    phony = Environment(
        ENV = os.environ,
        BUILDERS = { 'phony' : Builder(action = action) })
    return AlwaysBuild(
        phony.phony(target = target, source = 'SConscript'))
        
def build_docs(target, source, env):
    root = Dir('#').abspath
    subprocess.call(
        ['doxygen'], 
        cwd=os.path.join(root, 'docs', 'doxygen'))
    subprocess.call(
        ['make', 'clean'],
        cwd=os.path.join(root, 'docs', 'sphinx', 'source'))
    subprocess.call(
        ['make', 'html'],
        cwd=os.path.join(root, 'docs', 'sphinx', 'source'))

Depends(PhonyTarget('docs', build_docs)[0], 'build')
